Skip to contents

Attaches arguments that fit_models passes to the fitting function along with the formula, data and weights. Use this for models not fully specified by their formula, such as ordinal::clm()'s nominal, glmmTMB::glmmTMB()'s ziformula, or a vcov or cluster specification.

Arguments survive add_terms, update.model_spec and the other spec helpers, and are shown by preview_fit.

The fitting function must accept them, through ... or as named arguments of its own (see fit_models). A function named by a string, e.g. fun = "clm", accepts them through .... fittr passes such a function the formula, data and weights itself, so arguments named formula, data or weights are rejected.

Arguments are passed as ordinary values, so arguments that a modelling function evaluates inside the data, notably subset and offset, do not work. Use offset(x) as a term instead, and pass fit_models a separate dataset in place of subset.

Usage

set_args(spec, ...)

Arguments

spec

A model_spec object.

...

Named arguments to add. A model_spec value is converted to a one-sided formula when the model is fitted, so formula-valued arguments can be built and changed with the term helpers. Other values are passed as given; note that a formula keeps the environment it was created in. Names already present are replaced, and a NULL value removes an argument. The names f, d and w are reserved.

Value

A new model_spec carrying the arguments.

Examples

base_m <- model_spec(x1, x2)

# A formula-valued argument built from terms
set_args(base_m, nominal = model_spec(x1))
#> model_spec: ~ x1 + x2 
#>   args: nominal = ~ x1 

# Any other value is passed through as given
set_args(base_m, link = "probit")
#> model_spec: ~ x1 + x2 
#>   args: link = "probit" 

# Arguments survive later term changes
set_args(base_m, nominal = model_spec(x1)) |> add_terms(x3)
#> model_spec: ~ x1 + x2 + x3 
#>   args: nominal = ~ x1